package com.hutu.service.biz.impl;

import cn.hutool.core.util.StrUtil;
import com.hutu.mapper.biz.BaseProjectMapper;
import com.hutu.model.biz.BaseProject;
import com.hutu.model.resp.Response;
import com.hutu.model.resp.ResponseVo;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.InputStream;
import java.net.URLEncoder;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import cn.hutool.poi.excel.ExcelReader;
import cn.hutool.poi.excel.ExcelUtil;
import cn.hutool.poi.excel.ExcelWriter;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hutu.service.biz.BaseProjectService;

/**
 * <p>
 *  服务类
 * </p>
 *
 * @author admin
 * @since 2024-05-10
 */
@Service
public class  BaseProjectServiceImpl extends ServiceImpl<BaseProjectMapper,BaseProject > implements BaseProjectService{

    public ResponseVo add(BaseProject baseProject){
        if(save(baseProject)){
            return Response.success();
        }
        return Response.error();
    }

    public ResponseVo deleteById(Integer id){
        if(removeById(id)){
            return Response.success();
        }
        return Response.error();
    }

    public ResponseVo deleteBatch(List<Integer> ids){
        if(removeBatchByIds(ids)){
            return Response.success();
        }
        return Response.error();
    }


    public ResponseVo edit(BaseProject baseProject){
        if(updateById(baseProject)){
            return Response.success();
        }
        return Response.error();
    }


    public ResponseVo findById(Integer id){
        BaseProject baseProject =getById(id);
        if(baseProject !=null){
            return Response.success(baseProject);
        }
        return Response.error();
    }


    public ResponseVo list(Integer current,Integer size,String name){
        IPage<BaseProject> config=new Page<>(current,size);
        QueryWrapper<BaseProject> wrapper=null;
        if(StrUtil.isNotBlank(name)){
            wrapper=new QueryWrapper<>();
            wrapper.like("table_name", StrUtil.format("%{}%",name));
            wrapper.or(w -> w.like("remark", StrUtil.format("%{}%",name)));
        }
        IPage<BaseProject> page=page(config,wrapper);
        // 将响应数据填充到map中
        Map map=new HashMap();
        map.put("pages",page.getPages());
        map.put("total",page.getTotal());
        map.put("list",page.getRecords());
        return Response.success(map);
    }

    @Override
    public List<BaseProject> findDataForSelect() {
        return baseMapper.selectList(null);
    }


}




